package com.base.andlang2.apollo

import android.os.Build
import com.apollographql.apollo3.api.http.HttpHeader
import com.base.andlangcore.util.LogUtils
import java.util.*

object HeadsHandle {
    private var defaultHeadsMap: Map<String, String?> = mapOf()
        get() = mapOf(
            "os" to "and",
            "osVersion" to Build.VERSION.RELEASE,
            "bean" to Build.MODEL,
            "brand" to Build.BRAND,
            "tz" to TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT),
            "language" to Locale.getDefault().language,
        )

    private var defaultHeads: ArrayList<HttpHeader> = arrayListOf()

    fun getHttpDfHeads(reset: Boolean): ArrayList<HttpHeader> {
        if (defaultHeads.isEmpty() || reset) {
            defaultHeads.clear()
            defaultHeadsMap.forEach { it ->
                if (it.value != null) {
                    defaultHeads.add(HttpHeader(it.key, it.value!!))
                    LogUtils.d("${it.key} ${it.value}")
                }
            }
        }
        return defaultHeads
    }
}